package cn.psvmc.cxzapi.controller.customer;

import cn.psvmc.cxzapi.model.common.SearchEntity;
import cn.psvmc.cxzapi.model.customer.TCustomerCoupon;
import cn.psvmc.cxzapi.model.store.TCoupon;
import cn.psvmc.cxzapi.response.PageResult2;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.customer.TCustomerCouponService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 客户优惠券管理
 * @Author auto
 * @Date 2024-08-15
 */
@RestController
@RequestMapping("/mpapi/customer_coupon")
public class TCustomerCouponController {

    @Resource
    private TCustomerCouponService tCustomerCouponService;

    /**
    * @Author auto 2024-08-15 新增客户优惠券表
    * @Param tCustomCoupon 客户优惠券表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TCoupon coupon) {
        ToolUtils.validation(new Object[]{coupon.getCouponid(), "优惠券id", 1});
        tCustomerCouponService.add(coupon);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 使用券码领券
     * @Date 2024/9/1 10:54
     * @Author YWX
     * @Param [coupon]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add2")
    public Result add2(@RequestBody TCoupon coupon) {
        ToolUtils.validation(new Object[]{coupon.getCouponCode(), "优惠券编码", 2});
        tCustomerCouponService.add2(coupon);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 领券中心
     * @Date 2024/8/15 17:24
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list")
    public PageResult2 list(@RequestBody SearchEntity entity) {
        Page<TCustomerCoupon> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tCustomerCouponService.list(queryPage, entity));
    }

    /**
     * @Description 我的优惠券列表
     * @Date 2024/8/15 17:26
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_my")
    public PageResult2 listMy(@RequestBody SearchEntity entity) {
        Page<TCustomerCoupon> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tCustomerCouponService.listMy(queryPage, entity));
    }
}
